{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "fixed-employment",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "southern-subsection",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd1 = np.array([1,2,3,4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "vietnamese-stephen",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4] <class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "print(nd1,type(nd1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "special-lightning",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd2 = np.array([[1,2,3,4,5],[6,7,8,9,10]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "later-labor",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  2  3  4  5]\n",
      " [ 6  7  8  9 10]]\n"
     ]
    }
   ],
   "source": [
    "print(nd2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "imported-eight",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd2.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "instructional-explanation",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd2.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "european-designation",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.8722813232690143"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd2.std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "suspected-proposition",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd3 = np.array([\"1\",\"2\",\"3\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "agreed-liechtenstein",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['1' '2' '3'] <class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "print(nd3,type(nd3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "separate-accent",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd4 = nd3.astype(\"int\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "original-click",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd4.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "latest-bottle",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd5 = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "exempt-springfield",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1  2  3  4]\n",
      " [ 5  6  7  8]\n",
      " [ 9 10 11 12]\n",
      " [13 14 15 16]]\n"
     ]
    }
   ],
   "source": [
    "print(nd5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "heard-folder",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 6,  7],\n",
       "       [10, 11]])"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd5[1:3:,1:3:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "meaningful-mainland",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4, 4)"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出大于10的所有元素\n",
    "nd5[nd5>10]\n",
    "nd5.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "collected-runner",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1,  2,  3,  4,  5,  6,  7,  8],\n",
       "       [ 9, 10, 11, 12, 13, 14, 15, 16]])"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd5.reshape(2,8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "legislative-egypt",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd1 = np.array([1,2,3,4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "wrapped-walker",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3 4]\n"
     ]
    }
   ],
   "source": [
    "print(nd1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "equivalent-camcorder",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 3])"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd1[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "under-camcorder",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd6 = np.array([\n",
    "    [0,1,2,3,4,5],\n",
    "    [10,11,12,13,14,15],\n",
    "    [20,21,22,23,24,25],\n",
    "    [30,31,32,33,34,35],\n",
    "    [40,41,42,43,44,45],\n",
    "    [50,51,52,53,54,55]\n",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "particular-graphics",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4,  5],\n",
       "       [10, 11, 12, 13, 14, 15],\n",
       "       [20, 21, 22, 23, 24, 25],\n",
       "       [30, 31, 32, 33, 34, 35],\n",
       "       [40, 41, 42, 43, 44, 45],\n",
       "       [50, 51, 52, 53, 54, 55]])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "impressive-corrections",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 2],\n",
       "       [12],\n",
       "       [22],\n",
       "       [32],\n",
       "       [42],\n",
       "       [52]])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd6[::,2:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "comic-portugal",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 4]])"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd6[0:1:,3:5:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "fatty-citizen",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[20, 22, 24],\n",
       "       [40, 42, 44]])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd6[2::2,::2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "billion-wiring",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1, 12, 23, 34, 45])"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd6[(0,1,2,3,4),(1,2,3,4,5)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "caring-beach",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2]\n",
      " [3 4]]\n"
     ]
    }
   ],
   "source": [
    "nd7 = np.array([[1,2],[3,4]])\n",
    "print(nd7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "external-environment",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[2 1]\n",
      " [1 2]]\n"
     ]
    }
   ],
   "source": [
    "nd8 = np.array([[2,1],[1,2]])\n",
    "print(nd8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "immediate-lounge",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 3],\n",
       "       [4, 6]])"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# + - * /\n",
    "nd7 + nd8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "adverse-testing",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1,  1],\n",
       "       [ 2,  2]])"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd7 - nd8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "large-happening",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2, 2],\n",
       "       [3, 8]])"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd7 * nd8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "geographic-rebecca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.5, 2. ],\n",
       "       [3. , 2. ]])"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd7 / nd8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "perceived-emergency",
   "metadata": {},
   "outputs": [],
   "source": [
    "nd9 = np.array([[1,2,3],[3,2,1]])\n",
    "nd10 = np.array([[1,2],[3,4],[5,6]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "charged-party",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2.26666667, 1.5       ],\n",
       "       [3.86666667, 2.16666667]])"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.dot(nd9,1/nd10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "warming-shield",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.0"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nd9.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "primary-deadline",
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "hundred-spectacular",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.21229156, 0.98679978, 0.29201715],\n",
       "       [0.80536449, 0.26535782, 0.69663427]])"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.rand(2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "pharmaceutical-retirement",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
